//
//  BViewController.m
//  BriefBookAnimation
//
//  Created by Burn on 2019/6/27.
//  Copyright © 2019 menksoft. All rights reserved.
//

#import "BViewController.h"
#import "PresentOneTransition.h"
#import "InteractiveTransition.h"
@interface BViewController ()

@property(strong,nonatomic) InteractiveTransition *interactiveTransition;

@end

@implementation BViewController

- (instancetype)init{
    if (self = [super init]) {
        self.transitioningDelegate = self;
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.interactiveTransition = [InteractiveTransition interactiveTransitionWithTransitionType:InteractiveTransitionTypeDismiss GestureDirection:GestureDirecationDown];
    [self.interactiveTransition addPanGestureForViewController:self];
    
}

- (IBAction)pop:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

//  返回一个管理prenent动画过渡的对象
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return [PresentOneTransition initWith:PresentOneTransitionTypePresent];
    
}
//  返回一个管理dismiss动画过渡的对象
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    return [PresentOneTransition initWith:PresentOneTransitionTypeDismiss];
}


//返回dissmiss的手势过渡管理
- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator{
    //在没有用手势触发的dismiss的时候需要传nil，否者无法点击dimiss，所以interation就是用来判断是否是手势触发转场的
    return self.interactiveTransition.interation ? self.interactiveTransition : nil;
}

//返回present的手势管理，这个手势管理者是在vc1中创建的，我用代理传过来的
- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id<UIViewControllerAnimatedTransitioning>)animator{
    InteractiveTransition *interactivePresent = [_delegate interactiveTransitionForPresent];
    return interactivePresent.interation ? interactivePresent : nil;
}

@end
